package threading;

public class ThreadDemo11 {
    public static void main(String[] args) {
        Thread t = new Thread( () -> {
            //currentThread()用于获取当前线程的实例，此处就是获取线程t，
            //isInterrupted()用于判断该线程是否被中断，上面Thread类的属性里提到
            while (!Thread.currentThread().isInterrupted()) {
                System.out.println("hello t");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    break;
                }
            }
        });
        t.start();


        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //将标志位设为true
        t.interrupt();
    }
}
